package br.unicamp.ic.lis.dbvapi.service.impl;

import org.genericspatialdao.dao.DAO;
import org.genericspatialdao.dao.DAOFactory;

import br.unicamp.ic.lis.dbvapi.service.Service;

public abstract class ServiceImpl<T> implements Service<T> {

	protected final Class<T> entityClass;
	protected DAO<T> dao;

	public ServiceImpl(Class<T> entityClass) {
		this.entityClass = entityClass;
	}

	@Override
	public DAO<T> getDAO() {
		if (dao == null) {
			dao = DAOFactory.getDAO(entityClass);
		}
		return dao;
	}

	@Override
	public void close() {
		if (dao != null) {
			getDAO().close();
			dao = null;
		}
	}
}
